package com.spring.demo2.eg1;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;

/**
 * BeanDefinitionRegistryPostProcessor有个非常重要的实现类：org.springframework.context.annotation.ConfigurationClassPostProcessor
 * 下面这些注解都是在上面这个类中实现的：
 * 1.@Configuration
 * 2.@ComponentScan
 * 3.@Import
 * 4.@ImportResource
 * 5.@PropertySource
 *
 * @author vhans
 */
@Component
public class MyBeanDefinitionRegistryPostProcessor1 implements BeanDefinitionRegistryPostProcessor, Ordered {
    @Override
    public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry beanDefinitionRegistry) throws BeansException {
        beanDefinitionRegistry.registerBeanDefinition("address", BeanDefinitionBuilder
                .genericBeanDefinition(String.class)
                .addConstructorArgValue("嘉兴")
                .getBeanDefinition());
    }

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException {

    }

    @Override
    public int getOrder() {
        return 2;
    }
}
